
var req = require('../../../utils/token.js');
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    prakTitle:{
      "flag": 2,
      "name": "我有票"
    }, 
    ticketTitle: {
      "flag": 1,
      "name": "我要停车"
    },
    title:{},
    isToDialogue: false,
    address: "",
    showModal: false,
    isSubmit: false,
    isSub: false,
    isPub: false,
    flag: 0,
    list:[],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (e) {
    if (app.globalData.userInfo == null || app.globalData.userInfo == '') {
      wx.showToast({
        title: '请先登录',
        icon: "none",
        duration: 1000
      })
      setTimeout(function () {
        wx.switchTab({
          url: '/pages/ticket/personal/personal'    //我的
        });
         }, 1000)
    }
    var url='';
    this.setData({
      flag: app.globalData.vtype  //component 页面用
    })
    this.setData({
     address: app.globalData.address
    }) 
    if (this.data.flag==0){
      url ="ticket/getTicketInfoBy";
      this.setData({
        title: this.data.prakTitle
      })

    }else{
      this.setData({
        title: this.data.ticketTitle
      })
      url = "park/parkInfoByCondition";
    };
    this.getlistpark(url);
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  },

    getlistpark:function(url){
      var header = req.CreateHeader();
      var _this = this
      var appData = app.globalData;
      if (appData.marketinfo==null){
        return false;
      }
      wx.request({
        url: appData.url + url,
        header: header,
        data: {
          marketId: appData.marketinfo.marketId,
          status: 1,
        },
        success: function (res) {
          console.log(res)
          if (res.statusCode == '200' && res.data != '9999' && res.data != false && res.data != null) {
            _this.setData({
              list:res.data
            })
           
            return true
          }
        },
        fail: function (res) {
          _this.setData({
            fail: false
          })
        }
      })
    },
    // getlistticket: function () {
    //   var header = req.CreateHeader();
    //   var _this = this
    //   var appData = app.globalData;
    //   if (appData.marketinfo == null) {
    //     return false;
    //   }
    //   wx.request({
    //     url: appData.url + "ticket/getTicketAll",
    //     header: header,
    //     data: {
    //       marketId: appData.marketinfo.marketId,
    //       status: 1,
    //     },
    //     success: function (res) {
    //       console.log(res)
    //       if (res.statusCode == '200' && res.data != '9999' && res.data != false && res.data != null) {


    //         return true
    //       }
    //     },
    //     fail: function (res) {
    //       _this.setData({
    //         fail: false
    //       })
    //     }
    //   })
    // },


  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },

  
  geocoder: function () {

console.log("geocoder")
  },

  submit: function () {
    this.setData({
      showModal: true
    })
  },

  toDialogue: function (event){
    let bookId = event.currentTarget.dataset.bookId
    this.insertMsg(bookId)
  },
  insertMsg:function(userid){
    var _this = this
   // userid = 'fa52f147f4854da0b95d04b072834ddb'                                                        //测试用    使用时删除
    if (userid == app.globalData.userInfo.uuid){  //点击自己发送的
      wx.showToast({
        title: '不能点击自己发送的消息~',
        icon: "none",
        duration: 1000
      })
      return 
    }
    var header = req.CreateHeader();
    wx.request({
      url: app.globalData.url + "msg/insertMsg",
      header: header,
      data: {
        userId1: userid,
        userId2: app.globalData.userInfo.uuid,
        address: app.globalData.address,
        status: 1,
      },
      success: function (res) {
        if (res.data>0){
          app.globalData.toDialogue = userid
          wx.switchTab({
            url: "/pages/ticket/message/message"
          }); 
        }else{
          wx.showToast({
            title: '超时了~',
            icon: "none",
            duration: 1000
          })
        }
      },
      fail: function (res) {
        wx.showToast({
          title: '超时了~',
          icon: "none",
          duration: 1000
        })
      }
    })
  }
})